<?php

/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitereview
 * @copyright  Copyright 2012-2013 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: Menus.php 6590 2013-04-01 00:00:00Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
class Sitereview_Plugin_Menus {

  public function canCreateSitereviews($row) {

    //MUST BE LOGGED IN USER
    $viewer = Engine_Api::_()->user()->getViewer();
    if (!$viewer || !$viewer->getIdentity()) {
      return false;
    }

    //GET LISTING TYPE ID
    $listingtype_id = $row->params['listingtype_id'];

    //MUST BE ABLE TO VIEW LISTINGS
    if (!Engine_Api::_()->authorization()->isAllowed('sitereview_listing', $viewer, "view_listtype_$listingtype_id")) {
      return false;
    }

    //MUST BE ABLE TO CRETE LISTINGS
    if (!Engine_Api::_()->authorization()->isAllowed('sitereview_listing', $viewer, "create_listtype_$listingtype_id")) {
      return false;
    }

    return true;
  }

  public function canViewSitereviews($row) {

    //GET VIEWER
    $viewer = Engine_Api::_()->user()->getViewer();

    //GET LISTING TYPE ID
    $listingtype_id = $row->params['listingtype_id'];

    //MUST BE ABLE TO VIEW LISTINGS
    if (!Engine_Api::_()->authorization()->isAllowed('sitereview_listing', $viewer, "view_listtype_$listingtype_id")) {
      return false;
    }

    // echo "<pre>".print_r($row->params,true)."</pre>";die;
    $hasCountry = Zend_Registry::isRegistered("listing_country");
    $request = Zend_Controller_Front::getInstance()->getRequest();
    $listingid = $request->getParam('listingtype_id',0);
    if ($hasCountry == true && $listingid == $listingtype_id && $row->name == "core_main_sitereview_listtype_".$listingtype_id){
        $route = $row->params;
        
        $country = Zend_Registry::get('listing_country');
        $route['label'] = $country->title .":".$row->label;
        return $route;
    }
    
    return true;
  }

  public function canViewBrosweReview($row) {

    //GET VIEWER
    $viewer = Engine_Api::_()->user()->getViewer();

    //MUST BE ABLE TO VIEW WISHLISTS
    if (!Engine_Api::_()->authorization()->isAllowed('sitereview_listing', $viewer, "view")) {
      return false;
    }
    $request = Zend_Controller_Front::getInstance()->getRequest();
    $listingtype_id = $request->getParam('listingtype_id');
    if (($listingtype_id && $listingtype_id > 0 ) || ($listingTypeCount = Engine_Api::_()->getDbTable('listingtypes', 'sitereview')->getListingTypeCount()) == 1) {
      if (!($listingtype_id && $listingtype_id > 0 ) && $listingTypeCount == 1)
        $listingtype_id = 1;
      Engine_Api::_()->sitereview()->setListingTypeInRegistry($listingtype_id);
      $listingtypeArray = Zend_Registry::get('listingtypeArray' . $listingtype_id);
      if (empty($listingtypeArray->reviews))
        return false;
    }
    if ($listingtype_id > 0) {
      $route['route'] = 'sitereview_review_browse_listtype_' . $listingtype_id;
      if ('sitereview' == $request->getModuleName() &&
              'review' == $request->getControllerName() &&
              'browse' == $request->getActionName()) {
        $route['active'] = true;
      }
      return $route;
    }
    return true;
  }

  public function canViewCategories($row) {
    
    //GET VIEWER
    $viewer = Engine_Api::_()->user()->getViewer();

    //MUST BE ABLE TO VIEW WISHLISTS
    if (!Engine_Api::_()->authorization()->isAllowed('sitereview_listing', $viewer, "view")) {
      return false;
    }
    $request = Zend_Controller_Front::getInstance()->getRequest();
    $listingtype_id = $request->getParam('listingtype_id');
    if (($listingtype_id && $listingtype_id > 0 ) || ($listingTypeCount = Engine_Api::_()->getDbTable('listingtypes', 'sitereview')->getListingTypeCount()) == 1) {
      if (!($listingtype_id && $listingtype_id > 0 ) && $listingTypeCount == 1)
        $listingtype_id = 1;

      $route['route'] = 'sitereview_review_categories_' . $listingtype_id;
      $route['action'] = 'categories';
      if ('sitereview' == $request->getModuleName() &&
              'index' == $request->getControllerName() &&
              'categories' == $request->getActionName()) {
        $route['active'] = true;
      } else {
        $route['active'] = false;
      }
      return $route;
    }
    return true;
  }

  public function canViewWishlist($row) {

    //GET VIEWER
    $viewer = Engine_Api::_()->user()->getViewer();

    //MUST BE ABLE TO VIEW WISHLISTS
    if (!Engine_Api::_()->authorization()->isAllowed('sitereview_listing', $viewer, "view")) {
      return false;
    }

    //MUST BE ABLE TO VIEW WISHLISTS
    if (!Engine_Api::_()->authorization()->isAllowed('sitereview_wishlist', $viewer, "view")) {
      return false;
    }

    $listingtype_id = 0;
    $listingTypeCount = Engine_Api::_()->getDbTable('listingtypes', 'sitereview')->getListingTypeCount();
    if ($listingTypeCount == 1) {
      $listingtype_id == 1;
    } else {
      $listingtype_id = Zend_Controller_Front::getInstance()->getRequest()->getParam('listingtype_id');
    }

    if (!empty($listingtype_id)) {
      Engine_Api::_()->sitereview()->setListingTypeInRegistry($listingtype_id);
      $listingtypeArray = Zend_Registry::get('listingtypeArray' . $listingtype_id);
      if (empty($listingtypeArray->wishlist)) {
        return false;
      }
    }

    return true;
  }

  public function canViewEditors($row) {

    //GET VIEWER
    $viewer = Engine_Api::_()->user()->getViewer();

    //MUST BE ABLE TO VIEW LISTINGS
    if (!Engine_Api::_()->authorization()->isAllowed('sitereview_listing', $viewer, "view")) {
      return false;
    }

    $editorsCount = Engine_Api::_()->getDbTable('editors', 'sitereview')->getEditorsCount(0);

    if ($editorsCount <= 0) {
      return false;
    }

    $listingtype_id = 0;
    $listingTypeCount = Engine_Api::_()->getDbTable('listingtypes', 'sitereview')->getListingTypeCount();
    if ($listingTypeCount == 1) {
      $listingtype_id == 1;
    } else {
      $listingtype_id = Zend_Controller_Front::getInstance()->getRequest()->getParam('listingtype_id');
    }

    if (!empty($listingtype_id)) {
      Engine_Api::_()->sitereview()->setListingTypeInRegistry($listingtype_id);
      $listingtypeArray = Zend_Registry::get('listingtypeArray' . $listingtype_id);
      if ($listingtypeArray->reviews == 2 || empty($listingtypeArray->reviews)) {
        return false;
      }
    }

    return true;
  }

  public function userProfileWishlist() {

    //GET VIEWER
    $viewer = Engine_Api::_()->user()->getViewer();

    //MUST BE ABLE TO VIEW WISHLISTS
    if (!Engine_Api::_()->authorization()->isAllowed('sitereview_wishlist', $viewer, "view")) {
      return false;
    }

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('user')) {
      return false;
    }

    $user = Engine_Api::_()->core()->getSubject('user');

    $wishlist_id = Engine_Api::_()->getDbtable('wishlists', 'sitereview')->getRecentWishlistId($user->user_id);

    if (!empty($wishlist_id)) {
      return array(
          'class' => 'buttonlink',
          'route' => 'sitereview_wishlist_general',
          'icon' => 'application/modules/Sitereview/externals/images/icons/wishlist.png',
          'params' => array(
            'text' => $user->getTitle(),
          ),
      );
    } else {
      return false;
    }
  }

  public function sitereviewGutterEdit($row) {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //GET VIEWER
    $viewer = Engine_Api::_()->user()->getViewer();

    //GET LISTING SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    //GET LISTING TYPE ID
    $listingtype_id = $row->params['listingtype_id'];

    //AUTHORIZATION CHECK
    if (!$sitereview->authorization()->isAllowed($viewer, "edit_listtype_$listingtype_id")) {
      return false;
    }

    return array(
        'class' => 'buttonlink seaocore_icon_edit',
        'route' => "sitereview_specific_listtype_$listingtype_id",
        'action' => 'edit',
        'params' => array(
            'listing_id' => $sitereview->getIdentity(),
        ),
    );
  }

  public function sitereviewGutterEditoverview($row) {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //GET VIEWER
    $viewer = Engine_Api::_()->user()->getViewer();

    //GET LISTING SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    //GET LISTING TYPE ID
    $listingtype_id = $row->params['listingtype_id'];

    $listingType = Zend_Registry::get('listingtypeArray' . $listingtype_id);

    if (empty($listingType->overview)) {
      return false;
    }

    if (!$sitereview->authorization()->isAllowed($viewer, 'edit_listtype_' . $sitereview->listingtype_id)) {
      return false;
    }

    if (!$sitereview->authorization()->isAllowed($viewer, 'overview_listtype_' . $sitereview->listingtype_id)) {
      return false;
    }

    return array(
        'class' => 'buttonlink sitereview_gutter_editoverview',
        'route' => "sitereview_specific_listtype_$listingtype_id",
        'action' => 'overview',
        'params' => array(
            'listing_id' => $sitereview->getIdentity(),
        ),
    );
  }

  public function sitereviewGutterEditstyle($row) {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //GET VIEWER
    $viewer = Engine_Api::_()->user()->getViewer();

    //GET LISTING SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    //GET LISTING TYPE ID
    $listingtype_id = $row->params['listingtype_id'];

    if (!$sitereview->authorization()->isAllowed($viewer, 'edit_listtype_' . $sitereview->listingtype_id)) {
      return false;
    }

    if (!$sitereview->authorization()->isAllowed($viewer, 'style_listtype_' . $sitereview->listingtype_id)) {
      return false;
    }

    return array(
        'class' => 'buttonlink sitereview_gutter_editstyle',
        'route' => "sitereview_specific_listtype_$listingtype_id",
        'action' => 'editstyle',
        'params' => array(
            'listing_id' => $sitereview->getIdentity(),
        ),
    );
  }

  public function sitereviewGutterShare() {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //GET SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    //GET VIEWER ID
    $viewer_id = Engine_Api::_()->user()->getViewer()->getIdentity();

    //RETURN IF VIEWER IS EMPTY
    if (empty($viewer_id)) {
      return false;
    }

    return array(
        'class' => 'smoothbox seaocore_icon_share buttonlink',
        'route' => 'default',
        'params' => array(
            'module' => 'activity',
            'controller' => 'index',
            'action' => 'share',
            'type' => $sitereview->getType(),
            'id' => $sitereview->getIdentity(),
            'format' => 'smoothbox',
        ),
    );
  }

  public function sitereviewGutterMessageowner($row) {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //GET VIEWER INFO
    $viewer = Engine_Api::_()->user()->getViewer();
    $viewer_id = $viewer->getIdentity();

    //RETURN IF NOT AUTHORIZED
    if (empty($viewer_id)) {
      return false;
    }

    //GET SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    //SHOW MESSAGE OWNER LINK TO USER IF MESSAGING IS ENABLED FOR THIS LEVEL
    $showMessageOwner = 0;
    $showMessageOwner = Engine_Api::_()->authorization()->getPermission($viewer->level_id, 'messages', 'auth');
    if ($showMessageOwner != 'none') {
      $showMessageOwner = 1;
    }

    //RETURN IF NOT AUTHORIZED
    if ($sitereview->owner_id == $viewer_id || empty($viewer_id) || empty($showMessageOwner)) {
      return false;
    }

    //GET LISTING TYPE ID
    $listingtype_id = $row->params['listingtype_id'];

    return array(
        'class' => 'smoothbox icon_sitereviews_messageowner buttonlink',
        'route' => "sitereview_specific_listtype_$listingtype_id",
        'action' => 'messageowner',
        'params' => array(
            'listing_id' => $sitereview->getIdentity(),
        ),
    );
  }

  public function sitereviewGutterTfriend($row) {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //GET SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    //GET LISTING TYPE ID
    $listingtype_id = $row->params['listingtype_id'];

    return array(
        'class' => 'smoothbox buttonlink icon_sitereviews_tellafriend',
        'route' => "sitereview_specific_listtype_$listingtype_id",
        'action' => 'tellafriend',
        'params' => array(
            'listing_id' => $sitereview->getIdentity(),
        ),
    );
  }

  public function sitereviewGutterPrint($row) {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //GET SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    //GET LISTING TYPE ID
    $listingtype_id = $row->params['listingtype_id'];

    return array(
        'class' => 'buttonlink icon_sitereviews_printer',
        'route' => "sitereview_specific_listtype_$listingtype_id",
        'action' => 'print',
        'target' => '_blank',
        'params' => array(
            'listing_id' => $sitereview->getIdentity(),
        ),
    );
  }

  public function sitereviewGutterPublish($row) {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //GET SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    //GET VIEWER ID
    $viewer_id = Engine_Api::_()->user()->getViewer()->getIdentity();

    //RETURN IF NOT AUTHORIZED
    if ($sitereview->draft != 1 || ($viewer_id != $sitereview->owner_id)) {
      return false;
    }

    //GET LISTING TYPE ID
    $listingtype_id = $row->params['listingtype_id'];

    return array(
        'class' => 'buttonlink smoothbox icon_sitereview_publish',
        'route' => "sitereview_specific_listtype_$listingtype_id",
        'action' => 'publish',
        'params' => array(
            'listing_id' => $sitereview->getIdentity()
        ),
    );
  }

  public function sitereviewGutterEditorPick($row) {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //GET SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    //GET VIEWER DETAILS
    $viewer = Engine_Api::_()->user()->getViewer();
    $viewer_id = Engine_Api::_()->user()->getViewer()->getIdentity();

    $isEditor = Engine_Api::_()->getDbTable('editors', 'sitereview')->isEditor($viewer_id, $sitereview->listingtype_id);

    if (empty($isEditor) && $viewer->level_id != 1) {
      return false;
    }

    //GET LISTING TYPE ID
    $listingtype_id = $row->params['listingtype_id'];

    return array(
        'class' => 'buttonlink icon_sitereviews_similar_item',
        'route' => "sitereview_editor_general_listtype_$listingtype_id",
        'action' => 'similar-items',
        'params' => array(
            'listing_id' => $sitereview->getIdentity()
        ),
    );
  }

  public function sitereviewGutterReview() {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //NON LOGGED IN USER CAN'T BE THE EDITOR
    $viewer_id = Engine_Api::_()->user()->getViewer()->getIdentity();
    if (empty($viewer_id)) {
      return false;
    }

    //GET SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    //GET LISTING TYPE ID
    $listingtype_id = $sitereview->listingtype_id;

    //CHECK EDITOR REVIEW IS ALLOWED OR NOT
    $allow_editor_review = Engine_Api::_()->getDbTable('listingtypes', 'sitereview')->getListingTypeColumn($listingtype_id, 'reviews');
    if (empty($allow_editor_review) || $allow_editor_review == 2) {
      return false;
    }

    //SHOW THIS LINK ONLY EDITOR FOR THIS LISTING TYPE
    $isEditor = Engine_Api::_()->getDbTable('editors', 'sitereview')->isEditor($viewer_id, $listingtype_id);
    if (empty($isEditor)) {
      return false;
    }

    //EDITOR REVIEW HAS BEEN POSTED OR NOT
    $params = array();
    $params['resource_id'] = $sitereview->listing_id;
    $params['resource_type'] = $sitereview->getType();
    $params['type'] = 'editor';
    $params['notIncludeStatusCheck'] = 1;
    $isEditorReviewed = Engine_Api::_()->getDbTable('reviews', 'sitereview')->canPostReview($params);

    $params = array();
    $params['listing_id'] = $sitereview->getIdentity();
    if (!empty($isEditorReviewed)) {

      $editorreview = Engine_Api::_()->getApi('settings', 'core')->getSetting('sitereview.editorreview', 0);
      $review = Engine_Api::_()->getItem('sitereview_review', $isEditorReviewed);
      if (empty($editorreview) && $viewer_id != $review->owner_id) {
        return false;
      }

      $label = Zend_Registry::get('Zend_Translate')->_('Edit an Editor Review');
      $action = 'edit';
      $params['review_id'] = $isEditorReviewed;
    } else {
      $label = Zend_Registry::get('Zend_Translate')->_('Write an Editor Review');
      $action = 'create';
    }

    return array(
        'label' => $label,
        'class' => 'buttonlink icon_sitereviews_review',
        'route' => "sitereview_extended_listtype_$listingtype_id",
        'controller' => 'editor',
        'action' => $action,
        'params' => $params,
    );
  }

  public function sitereviewGutterClose() {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //GET SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    //GET VIEWER ID
    $viewer_id = Engine_Api::_()->user()->getViewer()->getIdentity();

    //RETURN IF NOT AUTHORIZED
    if ($viewer_id != $sitereview->owner_id) {
      return false;
    }

    $listingType = Zend_Registry::get('listingtypeArray' . $sitereview->listingtype_id);
    $title_singular = ucfirst($listingType->title_singular);

    if (!empty($sitereview->closed)) {
      $label = Zend_Registry::get('Zend_Translate')->_('Open');
      $class = 'buttonlink icon_sitereviews_open';
    } else {
      $label = Zend_Registry::get('Zend_Translate')->_('Close');
      $class = 'buttonlink icon_sitereviews_close';
    }

    $label = sprintf($label, $title_singular);

    return array(
        'label' => $label,
        'class' => $class,
        'route' => 'sitereview_specific_listtype_' . $sitereview->listingtype_id,
        'params' => array(
            'action' => 'close',
            'listing_id' => $sitereview->getIdentity()
        ),
    );
  }

  public function sitereviewGutterDelete($row) {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //GET VIEWER ID
    $viewer_id = Engine_Api::_()->user()->getViewer()->getIdentity();

    //GET SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    //GET LISTING TYPE ID
    $listingtype_id = $row->params['listingtype_id'];

    //LISTING DELETE PRIVACY
    $can_delete = $sitereview->authorization()->isAllowed(null, "delete_listtype_$listingtype_id");

    //AUTHORIZATION CHECK
    if (empty($can_delete) || empty($viewer_id)) {
      return false;
    }

    return array(
        'class' => 'buttonlink seaocore_icon_delete',
        'route' => 'sitereview_specific_listtype_' . $listingtype_id,
        'params' => array(
            'action' => 'delete',
            'listing_id' => $sitereview->getIdentity()
        ),
    );
  }

  public function sitereviewGutterReport() {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //GET VIEWER ID
    $viewer_id = Engine_Api::_()->user()->getViewer()->getIdentity();

    if (empty($viewer_id)) {
      return false;
    }

    //GET SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    return array(
        'class' => 'smoothbox buttonlink icon_sitereviews_report',
        'route' => 'default',
        'params' => array(
            'module' => 'core',
            'controller' => 'report',
            'action' => 'create',
            'route' => 'default',
            'subject' => $sitereview->getGuid()
        ),
    );
  }

  public function sitereviewGutterWishlist($row) {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //GET VIEWER
    $viewer = Engine_Api::_()->user()->getViewer();

    //GET LISTING SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    //AUTHORIZATION CHECK
    if (!empty($sitereview->draft) || empty($sitereview->search) || empty($sitereview->approved)) {
      return false;
    }

    //GET LISTING TYPE ID
    $listingtype_id = $row->params['listingtype_id'];

    //CHECK LISTINGTYPE WISHLIST ALLOWED OR NOT
    $wishlistAllow = Engine_Api::_()->getDbTable('listingtypes', 'sitereview')->getListingTypeColumn($listingtype_id, 'wishlist');
    if (empty($wishlistAllow)) {
      return false;
    }

    //AUTHORIZATION CHECK
    if (!Engine_Api::_()->authorization()->isAllowed('sitereview_wishlist', $viewer, 'view')) {
      return false;
    }

    return array(
        'class' => 'buttonlink smoothbox sr_icon_wishlist_add',
        'route' => "sitereview_wishlist_general",
        'action' => 'add',
        'params' => array(
            'listing_id' => $sitereview->getIdentity(),
        ),
    );
  }

  public function sitereviewGutterChangephoto($row) {

    //RETURN FALSE IF SUBJECT IS NOT SET
    if (!Engine_Api::_()->core()->hasSubject('sitereview_listing')) {
      return false;
    }

    //GET VIEWER
    $viewer = Engine_Api::_()->user()->getViewer();

    //GET LISTING SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    //GET LISTING TYPE ID
    $listingtype_id = $row->params['listingtype_id'];

    //AUTHORIZATION CHECK
    if (!$sitereview->authorization()->isAllowed($viewer, "edit_listtype_$listingtype_id")) {
      return false;
    }

    return array(
        'class' => 'buttonlink icon_sitereview_edit',
        'route' => "sitereview_specific_listtype_$listingtype_id",
        'action' => 'change-photo',
        'params' => array(
            'listing_id' => $sitereview->getIdentity(),
        ),
    );
  }

  public function sitereviewGutterSubscription($row)
  {
    //CHECK VIEWER
    $viewer = Engine_Api::_()->user()->getViewer();

    //GET LISTING SUBJECT
    $sitereview = Engine_Api::_()->core()->getSubject('sitereview_listing');

    if( $sitereview->owner_id == $viewer->getIdentity()) {
      return false;
    }
   
    $listingtype_id = $sitereview->listingtype_id;    

    //GET LISTING TYPE ID
    $listingType = Zend_Registry::get('listingtypeArray' . $listingtype_id);

    //CHECK EDITOR REVIEW IS ALLOWED OR NOT
    $allow_subscription = Engine_Api::_()->getDbTable('listingtypes', 'sitereview')->getListingTypeColumn($listingtype_id, 'subscription');
    if (empty($allow_subscription)) {
      return false;
    }

    //MODIFY PARAMS
    $subscriptionTable = Engine_Api::_()->getDbtable('subscriptions', 'sitereview');
    $owner = Engine_Api::_()->getItem('user', $sitereview->owner_id);

    if( !$subscriptionTable->checkSubscription($owner, $viewer, $listingtype_id) ) {
      $label = Zend_Registry::get('Zend_Translate')->_('Subscribe');
      $class = 'buttonlink smoothbox icon_sitereview_subscribe';
      $action = 'add';
    } else {
      $label = Zend_Registry::get('Zend_Translate')->_('Unsubscribe');
      $class = 'buttonlink smoothbox icon_sitereview_unsubscribe';
      $action = 'remove';
    }

		return array(
          'label' => $label,
					'class' => $class,
					'route' => "sitereview_subscription_listtype_$listingtype_id",
					'action' => $action,
					'params' => array(
							'listing_id' => $sitereview->getIdentity(),
					),
			);
  }

}
